import 'package:flutter/material.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:flutter_base/widgets/keyboard/tap_hide_keyboard.dart';

import 'application.dart';
import 'config/app_config.dart';
import 'config/app_routes.dart';
import 'config/app_theme.dart';

void main() async {
  WidgetsBinding _ = WidgetsFlutterBinding.ensureInitialized();
  await Application().initialize();
  await AppConfig.setup();
  
  // 使用闪屏页作为应用入口
  runApp(MyApp(
    title: AppConfig.appName,
  ));
}

class MyApp extends StatelessWidget {
  final String title;
  final bool useDefaultNavigation;

  const MyApp({super.key, required this.title, this.useDefaultNavigation = true});

  @override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
      designSize: const Size(375, 812),
      builder: (context, child) {
        return GetMaterialApp(
          title: title,
          debugShowCheckedModeBanner: false,
          transitionDuration: const Duration(milliseconds: 210),
          theme: AppTheme.setImaginifyTheme(),
          initialRoute: useDefaultNavigation ? AppRoutes.splash : Application.initialRoute(),
          getPages: AppRoutes.pages,
          builder: (context, widget) {
            return MediaQuery(
              data: MediaQuery.of(context).copyWith(textScaler: const TextScaler.linear(1.0)),
              child: FlutterEasyLoading(
                child: TapHideKeyboard(child: widget!),
              ),
            );
          },
        );
      },
    );
  }
}
